package cn.chenhao.order.controller;

import cn.chenhao.basic.util.AjaxResult;
import cn.chenhao.basic.util.LoginContext;
import cn.chenhao.basic.util.PageList;
import cn.chenhao.order.domain.AdoptOrder;
import cn.chenhao.order.query.AdoptOrderQuery;
import cn.chenhao.order.service.IAdoptOrderService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@Api(tags = "领养订单接口",description = "领养订单接口接口详细描述")
@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {
    @Autowired
    private IAdoptOrderService adoptOrderService;


    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){

        try{
            String data = adoptOrderService.submit(params, LoginContext.currentLoginInfo(request));
            return AjaxResult.me().setResultObj(data);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }

    }

    // 平台员工和店铺员工的订单列表
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.admin(query,LoginContext.currentLoginInfo(request));
    }

    // 用户订单
    @PostMapping("/user")
    public PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.user(query,LoginContext.currentLoginInfo(request));
    }

    @GetMapping("/{id}")
    public AdoptOrder getInfo(@PathVariable("id") Long id){
        return adoptOrderService.findById(id);
    }
}
